﻿using System;
using NUnit.Framework;
using Contacts;
using System.Diagnostics;
using MySql.Data.MySqlClient;
using ConfigLibrary;
using System.Security;
using System.Collections.Generic;

namespace Testing
{
	[TestFixture]
	public class MySqlTest
	{
		private Process mysql;

		[SetUp]
		public void StartMysql()
		{
			mysql = new Process();
			var arguments = new[] {
				"--standalone",
				"--console",
				"--basedir=.",
				"--language=.",
				"--datadir=.",
				"--skip-grant-tables",
				"--skip-networking",
				"--enable-named-pipe"
			};

			mysql.StartInfo.FileName = "../../../../mysqld";
			mysql.StartInfo.Arguments = string.Join(" ", arguments);
			mysql.StartInfo.UseShellExecute = false;
			mysql.StartInfo.CreateNoWindow = true;

			mysql.Start();
		}

		[TearDown]
		public void KillMySql()
		{
			mysql.Kill();
		}

		[TestCase]
		public void SqlStatment ()
		{
		}

	}

	[TestFixture]
	public class TestClass
	{

		[TestCase]
		public void PhoneTest()
		{
			string string2 = "123456789";
			string result = func.removecharacters("1-2-3-4-5-6-7-8-9");
			StringAssert.AreEqualIgnoringCase(string2, result);
			result = func.removecharacters("1@##$$$2MGKK3mkl4?\\}5/6`7+8||9{}");
			StringAssert.AreEqualIgnoringCase(string2, result);
		}

		[TestCase]
		public void FlexString()
		{
			const string controlstring = "TestString`'788{}}][";
			SecureString teststring = controlstring.ConvertToSecureString();
			Assert.True(controlstring == teststring.ConvertToUnsecureString(), "SecureString to Unsecurestring failed");
		}
		
		[TestCase]
		public void FlexUTF8String ()
		{
			const string controlstring = @"^7\hhhjJI%%\\0(()######||||\\\\\RrRrRrÁÁëðɑẽÑñ";
			SecureString teststring = controlstring.ConvertToSecureString();
			Assert.True(controlstring == teststring.ConvertToUnsecureString(), "SecureString to Unsecurestring failed");
		}
	}

	[TestFixture]
	public class WorkbenchTest 
	{
		public class BenchTest : Workbench.Bench
		{
			public BenchTest() : base ()
			{
				base.projects = ProjectTypes.None;
			}
			public ProjectTypes projType 
			{
				get { return base.projects;}
			}

			public void ProjectTypeChanger(ProjectTypes ProjectType)
			{
				base.ProjectTypeChanger(ProjectType);
			}
		}
		[TestCase]
		public void CycleProjectEnumerator()
		{
			BenchTest test = new BenchTest();
			Assert.AreEqual(ProjectTypes.None, test.projType);
			var type = new[] {ProjectTypes.Expansion,
				ProjectTypes.Fixturing, ProjectTypes.GroundUp,
				ProjectTypes.Remodel, ProjectTypes.RemodelC,
				ProjectTypes.Special, ProjectTypes.TakeOver};
			foreach (var item in type) {
				test.ProjectTypeChanger(item);
			}
			StringAssert.Contains("Remodel, RemodelC, " +
				"Expansion, TakeOver, GroundUp, Fixturing, Special",
			                                  test.projType.ToString());
			test.ProjectTypeChanger(ProjectTypes.Special);
			StringAssert.Contains("Remodel, RemodelC, " +
				"Expansion, TakeOver, GroundUp, Fixturing",
			                                  test.projType.ToString());
			test.ProjectTypeChanger(ProjectTypes.Fixturing | ProjectTypes.GroundUp);
			StringAssert.Contains("Remodel, RemodelC, " +
				"Expansion, TakeOver", test.projType.ToString());
			test.ProjectTypeChanger(ProjectTypes.GroundUp);
			StringAssert.Contains("Remodel, RemodelC, " +
				"Expansion, TakeOver, GroundUp",
			                                  test.projType.ToString());
		}
		public class BenchSqlConnector 
		{
			public BenchSqlConnector():
				base()
			{
			}
			public string TestEnumOnSwitch(ProjectTypes projects)
			{

				// TODO: build a string of 'prj_typ' using |'s to inject into the command statement.
				// Returns a string must be "AND prj_typ = <type> OR prj_typ = <type> OR ..."
				//Wal-Mart types are: EXP, NEW, REL, RMC, T/O, OSR, LND-NEW, LND-T/O
				List<string> filter = new List<string>();
				var typevalues = Enum.GetValues(typeof(ProjectTypes));
				foreach (ProjectTypes value in typevalues) {
					if ((projects & value) == value) {
						switch (value) {
						#region cases
							case ProjectTypes.Expansion:
								filter.Add("prj_typ = 'EXP'");
								break;
							case ProjectTypes.Fixturing:
								filter.Add("prj_typ = 'FIX'");
								break;
							case ProjectTypes.GroundUp:
								filter.Add("prj_typ = 'NEW'");
								break;
							case ProjectTypes.Remodel:
								filter.Add("prj_typ = 'REM'");
								break;
							case ProjectTypes.RemodelC:
								filter.Add("prj_typ = 'RMC'");
								break;
							case ProjectTypes.Special:
								filter.Add("prj_typ = 'SPC'");
								break;
							case ProjectTypes.TakeOver:
								filter.Add("prj_typ = 'T/O'");
								break;
							case ProjectTypes.Tenant:
								filter.Add("prj_typ = 'TEN'");
								break;
							case ProjectTypes.LandBank:
								filter.Add("prj_typ = 'LND-NEW'");
								filter.Add("prj_typ = 'LND-T/O'");
								break;
							case ProjectTypes.OnSiteRelo:
								filter.Add("prj_typ = 'OSR'");
								break;
							case ProjectTypes.Relo:
								filter.Add("prj_typ = 'REL'");
								break;
							#endregion
						}
					}
				}
				string result = string.Empty;
				#if DEBUG
				filter.Sort();
				#endif
				if (filter.Count == 1) {
					result = "AND " + filter [0];
				} else {
					result = "AND ";
					foreach (string storecommand in filter) {
						result += storecommand + " OR ";
					}
					result = result.Remove(result.Length - 4, 4);
			}
			return result;
		}
		

		}
		[TestCase]
		public void TestEnums1()
		{
			BenchSqlConnector makestring = new BenchSqlConnector();
			StringAssert.Contains(
				"AND prj_typ = 'EXP'", 
			    makestring.TestEnumOnSwitch(ProjectTypes.Expansion)
				);
		}
		[TestCase]
		public void TestEnums2()
		{
			BenchSqlConnector makestring = new BenchSqlConnector();
			StringAssert.AreEqualIgnoringCase(
				"AND prj_typ = 'EXP' OR prj_typ = 'REM' OR prj_typ = 'RMC' OR prj_typ = 'T/O'",
				makestring.TestEnumOnSwitch(
				ProjectTypes.Remodel | ProjectTypes.RemodelC | ProjectTypes.Expansion | ProjectTypes.TakeOver)
				);
		}
		[TestCase]
		public void TestEnums3()
		{
			BenchSqlConnector makestring = new BenchSqlConnector();
			StringAssert.AreEqualIgnoringCase(
				"AND prj_typ = 'REL' OR prj_typ = 'T/O'",
				makestring.TestEnumOnSwitch(
				ProjectTypes.TakeOver | ProjectTypes.Relo)
				);
		}
	}
}

namespace MailClient.Tests
{
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using MailClient.Handlers;

    [TestFixture]
    class Test
    {
        
		public void SpamTest()
		{
			string input = System.IO.File.ReadAllText(@"../../spamemail/emails");
			Test_Facade spammer = new Test_Facade();
			spammer.RunMail(input);
			Assert.IsTrue(spammer.SpamResult);
        }

        
        public void MailTest()
        {
            
        }
    }
}

namespace Utils
{
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

    public class Randomizer
    {

        Object Instantiation;
        private static Randomizer me = null;
        private static string lockObj = "";

        public static Randomizer Instance
        {
            get
            {
                lock (lockObj)
                {
                    if (me == null)
                    {
                        me = new Randomizer();
                    }

                    return me;
                }
            }
        }
        private Randomizer()
        {
            rand = new Random(DateTime.Now.ToString().GetHashCode());
        }

        

        string[] dictionary = new string[] { "abbreviation", "abbreviations", "abettor", "abettors", ".etc" };
        Random rand = null;

        public string GetRandomWords(int minWords, int maxWords)
        {
            int wrdCount = maxWords - minWords;
            StringBuilder sb = new StringBuilder(wrdCount * 10); //initial size to speed up appends

            //for each required word get a random one out of the dictionary
            for (int i = 0; i < wrdCount; i++)
            {
                //take care to add a space between the words
                if (sb.Length > 0)
                    sb.Append(" ");

                //add randomized word
                sb.Append(dictionary[rand.Next(0, dictionary.Length - 1)]);
            }

            //result!
            return sb.ToString().Trim();
        }
    }
}
